$(function (){
    $('#top-two').load('/front/top-two.html')
    $('#foot').load('/front/foot.html')

    //获取私教
    $.get({
        url: 'http://localhost:8080/teacher/find',
        dataType: 'json',
        success(res) {
            if(res.data.length>0){
                $('#teacher').empty();
                let count=0;
                for (const datum of res.data) {
                    count++;
                    let div='<div class="justify-content-center flex-wrap">\n' +
                        '                                    <img src="'+datum.imageLocation+'">\n' +
                        '                                    <div>'+datum.teacherName+'</div>\n' +
                        '                                    <div>\n' +
                        '                                        '+datum.level+'\n' +
                        '                                    </div>\n' +
                        '                                </div>'
                    $('#teacher').append(div);
                    if(count>=6)
                        break;
                }
            }
        }
    })
})

function sendContact(){
    let userName=$('#userName').val();
    let phone=$('#phone').val();
    let email=$('#email').val();
    let contact=$('#content').val();

    if(userName===''||phone===''||email===''||contact===''){
        alert('亲，你有选项没输入哦！');
    }else if(!(/^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/.test(phone))){
        alert('亲，手机号不规范哦~');
    }else if(!(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/.test(email))){
        alert('亲，邮箱是我们联系你的重要方式，请填写正确的邮箱哦~')
    }else{
        let data={
            "userName": userName,
            "phone": phone,
            "email": email,
            "content": contact
        }
        $.post({
            url:'http://localhost:8080/contact/add',
            data: data,
            dataType:'json',
            success(res){
                if(res.code>0)
                    alert('出现问题了呢~请稍后重试哦^-^')
                else
                    alert('发送成功，请耐心等待通知哦~')
            }
        })
    }
}